package com.stu.exercise.controller;

import com.stu.exercise.entity.Customer;
import com.stu.exercise.entity.R;
import com.stu.exercise.entity.User;
import com.stu.exercise.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @RequestMapping("/list")
    public R list(){
        return customerService.getCustomerList();
    }

    @RequestMapping("/add")
    public R add(@RequestBody Customer customer){
        return customerService.addCustomer(customer);
    }

    @RequestMapping("/edit")
    public R edit(@RequestBody Customer customer){
        return customerService.editCustomer(customer);
    }

    @RequestMapping("/delete/{id}")
    public R delete(@PathVariable Integer id){
        boolean remove = customerService.removeById(id);
        if (remove){
            return R.success("删除成功", null);
        }
        return R.error(500, "删除失败");
    }

}
